package com.sample.base

import android.view.View
import android.widget.TextView
import androidx.annotation.IdRes
import androidx.recyclerview.widget.RecyclerView

/**
 *  @Author Created by Z on 2020/4/14 星期二 17:33
 *  @Desc :
 */
abstract class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  private val viewMap = hashMapOf<Int, View>()

  internal fun <T : View> getView(@IdRes id: Int): T {
    var view = viewMap[id]
    if (view == null) {
      view = itemView.findViewById(id)
      viewMap[id] = view
    }
    return view as T
  }

  internal fun setText(@IdRes id: Int, text: String?) {
    getView<TextView>(id).text = text
  }
}